<?php
declare (strict_types = 1);

namespace app\admin\controller;

use app\admin\validate\AdminRoleValidate;
use think\facade\View;
use think\Request;
use app\admin\model\AdminRoles as AdminRoleModel;
use app\admin\model\AdminMenus;

class Adminroles extends Common
{
    protected $modelClass = AdminRoleModel::class;
    protected $detailWithModel = ['menus'];
    protected $validator   = AdminRoleValidate::class;

    protected function setSearchWhereFilter(array &$params = []):void
    {
        parent::setSearchWhereFilter($params); // TODO: Change the autogenerated stub

        if (isset($params['search']) && !empty($params['search'])){
            $params['where'][] = ['role_name', 'like', '%' . $params['search'] . '%'];
        }

        if ( isset($params['is_check']) && $params['is_check'] > -1 ) {
            $params['where'][] = ['is_check', '=', $params['is_check']];
        }
    }

    public function detail()
    {
        View::assign('menus', AdminMenus::getInstance()->getSelectLists());

        return parent::detail(); // TODO: Change the autogenerated stub
    }

    public function update(Request $request)
    {
        if ($request->param($this->model->getPk(), 0) == 1){
            return $this->errorJson('禁止编辑操作！');
        }

        return parent::update($request); // TODO: Change the autogenerated stub
    }

    public function delete(Request $request)
    {
        if ($request->param($this->model->getPk(), 0) == 1){
            return $this->errorJson('禁止删除操作！');
        }

        return parent::delete($request); // TODO: Change the autogenerated stub
    }
}
